package cn.yangliu.service.impl;

import cn.yangliu.entity.Dictionary;
import cn.yangliu.jpa.base.service.impl.JpaServiceImpl;
import cn.yangliu.repository.DictionaryRepository;
import cn.yangliu.service.DictionaryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author 问道于盲
 * @date 2021-09-28
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class DictionaryServiceImpl extends JpaServiceImpl<Dictionary, Long, DictionaryRepository> implements DictionaryService {

    /**
     * 根据分组名查询一组数据字典
     *
     * @param groupName 分组名
     * @return 一组数据字典
     */
    @Override
    public List<Dictionary> findByGroupName(String groupName) {
        return repository.findByGroupName(groupName);
    }

    /**
     * 根据name 查询
     *
     * @param name key
     *
     * @return 数据字典
     */
    @Override
    public Optional<Dictionary> findByName(String name) {
        return repository.findByName(name);
    }

    /**
     * 根据name 查询
     *
     * @param name key
     *
     * @return 数据字典
     */
    @Override
    public Dictionary findByKey(String name) {
        return repository.findByName(name).orElse(new Dictionary());
    }
}
